<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.Application</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_application_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Spec - howl.Application</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.application">howl.Application</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">root_dir</span><span class="p">,</span><span class="w"> </span><span class="n">application</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">root_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="p">.</span><span class="n">tmpdir</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">application</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Application</span><span class="w"> </span><span class="n">root_dir</span><span class="p">,</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">root_dir</span><span class="o">\</span><span class="n">delete_all</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".buffers-are-sorted-by-visibility-status-and-last_shown">.buffers are sorted by visibility status and last_shown</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">sci</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Scintilla</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">hidden_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">hidden_buffer</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hidden'</span><span class="w">&#x000A;&#x000A;</span><span class="n">last_shown_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="n">last_shown_buffer</span><span class="w">&#x000A;</span><span class="n">last_shown_buffer</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'last_shown'</span><span class="w">&#x000A;&#x000A;</span><span class="n">visible_buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">visible_buffer</span><span class="w">&#x000A;</span><span class="n">visible_buffer</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'visible'</span><span class="w">&#x000A;&#x000A;</span><span class="n">buffers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="n">b</span><span class="p">.</span><span class="n">title</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">application</span><span class="p">.</span><span class="n">buffers</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'visible'</span><span class="p">,</span><span class="w"> </span><span class="s1">'last_shown'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hidden'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">buffers</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="new_buffer">new_buffer<span class="arg-list">(mode)</span></h2>&#x000A;&#x000A;<h4 id="creates-a-new-buffer-with-mode">creates a new buffer with mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'default'</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="w"> </span><span class="n">m</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">m</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="uses-the-default-mode-if-no-mode-is-specifed">uses the default mode if no mode is specifed</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'default'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="p">.</span><span class="n">name</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="registers-the-new-buffer-in-.buffers">registers the new buffer in .buffers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">application</span><span class="p">.</span><span class="n">buffers</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="open_file">open_file<span class="arg-list">(file, editor)</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">editor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Editor</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="opens-the-file-in-the-specified-editor-if-given">opens the file in the specified editor if given</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'well hello there'</span><span class="w">&#x000A;  </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-the-newly-created-buffer">returns the newly created buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="adds-the-buffer-to-@buffers">adds the buffer to @buffers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">buffer</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">application</span><span class="p">.</span><span class="n">buffers</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="fires-the-file-opened-signal">fires the file-opened signal</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_signal_handler</span><span class="w"> </span><span class="s1">'file-opened'</span><span class="p">,</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">handler</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">handler</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when &lt;file&gt; is already open)</span></h3>&#x000A;&#x000A;<h4 id="switches-to-editor-to-the-existing-buffer-instead-of-creating-a-new-one">switches to editor to the existing buffer instead of creating a new one</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'a.foo'</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'b.foo'</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">application</span><span class="o">\</span><span class="n">open_file</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">application</span><span class="p">.</span><span class="n">buffers</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">editor</span><span class="p">.</span><span class="n">buffer</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="synchronize">synchronize<span class="arg-list">()</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when a buffer's file has changed on disk)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">b</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">reload</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">application</span><span class="o">\</span><span class="n">new_buffer</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b</span><span class="p">.</span><span class="n">reload</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">reload</span><span class="w">&#x000A;  </span><span class="nb">rawset</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="s1">'modified_on_disk'</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-buffer-is-reloaded-automatically-if-it-is-not-modified">the buffer is reloaded automatically if it is not modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">application</span><span class="o">\</span><span class="n">synchronize</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">reload</span><span class="p">).</span><span class="n">was_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="the-buffer-is-not-reloaded-automatically-if-it-is-modified">the buffer is not reloaded automatically if it is modified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">b</span><span class="p">.</span><span class="n">modified</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">application</span><span class="o">\</span><span class="n">synchronize</span><span class="o">!</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">b</span><span class="p">.</span><span class="n">reload</span><span class="p">).</span><span class="n">was_not_called</span><span class="o">!</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
